package com.yn.pet.controller.app;


import com.yn.common.annotation.Log;
import com.yn.common.core.domain.AjaxResult;
import com.yn.pet.controller.pc.biz.DeviceInfoBizService;
import com.yn.pet.entity.DeviceGroup;
import com.yn.pet.service.DeviceGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 * 设备组信息表 前端控制器
 * </p>
 *
 * @author xuquanjun
 * @since 2025-07-15
 */
@RestController
@RequestMapping("/front/group")
@Api(tags = "app端——设备组信息管理")
@RequiredArgsConstructor
@Slf4j
public class ADeviceGroupController {
    private final  DeviceGroupService deviceGroupService;

    /**
     * 保存设备组信息
     * @param name 设备组名称
     * @return
     */
    @PostMapping("save")
    @ApiOperation("添加设备组信息")
    public AjaxResult save(@RequestParam @NotNull String name) {
        deviceGroupService.saveGroup(name);
        return AjaxResult.success("添加成功");
    }

    /**
     * 修改设备组信息
     * @param name 设备组名称
     * @param groupId 设备组id
     * @return
     */
    @PostMapping("update")
    @ApiOperation("修改设备组信息")
    public AjaxResult update(@RequestParam @NotNull Long groupId,@RequestParam @NotNull String name) {
        deviceGroupService.updateGroup(groupId, name);
        return AjaxResult.success("修改成功");
    }

    /**
     * 删除设备组
     * @param groupId 设备组id
     * @return
     */
    @GetMapping("delete/{groupId}")
    @ApiOperation("删除设备组")
    public AjaxResult delete(@PathVariable @NotNull Long groupId) {
        deviceGroupService.removeGroup(groupId);
        return AjaxResult.success("删除成功");
    }


    /**
     * 分页查询设备组
     * @param currentPage 当前页
     * @param pageSize 每页数量
     * @return
     */
   /* @GetMapping("pageList")
    @ApiOperation("设备组列表")
    public AjaxResult list(@RequestParam(defaultValue = "1", required = false) Integer currentPage,
                           @RequestParam(defaultValue = "10", required = false) Integer pageSize) {

        return AjaxResult.success(deviceGroupService.pageList(currentPage, pageSize));
    }*/


    /**
     * 分页查询设备组
     * @param currentPage 当前页
     * @param pageSize 每页数量
     * @return
     */
    @GetMapping("pageList")
    @ApiOperation("设备组列表")
    public AjaxResult list1(@RequestParam(defaultValue = "1", required = false) Integer currentPage,
                           @RequestParam(defaultValue = "10", required = false) Integer pageSize) {
        log.info("分页查询设备组列表信息入参：currentPage:{},pageSize:{}",currentPage,pageSize);
        return AjaxResult.success(deviceGroupService.pageList1(currentPage, pageSize));
    }

    /**
     * 设备组详情
     * @param groupId 设备组Id
     * @return 设备组信息
     */
    @GetMapping("detail")
    @ApiOperation("设备组详情")
    public AjaxResult detail(@RequestParam @NotNull Long groupId) {

        return AjaxResult.success(deviceGroupService.getGroupInfo(groupId));
    }

}
